package com.xinxin.leetcode.problem225;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @author ShiXinXin
 * @date 2019-08-29 16:37
 */
class MyStack {
    Queue<Integer> queue = new LinkedList<>();

    /**
     * Initialize your data structure here.
     */
    public MyStack() {

    }

    /**
     * Push element x onto stack.
     */
    public void push(int x) {
        queue.add(x);
        int len = queue.size() - 1;
        while (len-- > 0) {
            queue.add(queue.peek());
            queue.remove();
        }
    }

    /**
     * Removes the element on top of the stack and returns that element.
     */
    public int pop() {
        return queue.remove();
    }

    /**
     * Get the top element.
     */
    public int top() {
        return queue.peek();
    }

    /**
     * Returns whether the stack is empty.
     */
    public boolean empty() {
        return queue.isEmpty();
    }
}
